const { DataTypes } = require("sequelize");

const seq = require("../DB/seq");

const Soft = seq.define(
  "mac_software",
  {
    softName: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true,
      comment: "软件的名字",
    },
    iconUrl: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "软件的icon图标",
    },
    softMenuInfo: {
      type: DataTypes.TEXT, // 使用 TEXT 类型代替 ARRAY
      allowNull: false,
      comment: "软件打开的时候左上方的菜单栏",
      get() {
        const value = this.getDataValue("softMenuInfo");
        return value ? value.split(",") : []; // 将字符串分割为数组
      },
      set(value) {
        this.setDataValue("softMenuInfo", value.join(",")); // 将数组连接为字符串
      },
    },
    softIsopen: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: false,
      comment: "软件是否被打开0关闭1打开",
    },
    softFocus: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: false,
      comment: "软件是否被聚焦默认值 false",
    },
    useTimes: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "软件被打开的次数",
    },
    softUrl: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "AppStore/",
    },
    FatherPath: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "AppStore/",
    },
    absolutePath: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "AppStore/",
    },
    relativePath: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "AppStore/",
    },
  },
  {
    paranoid: true,
  }
);

module.exports = Soft;
